<?php
/**
 * Created by PhpStorm.
 * User: PX780
 * Date: 2016/11/2
 * Time: 20:33
 */
$db = new mydb();

$admin = new AdminUser();
if(isset($_COOKIE['u_c_']) && preg_match("/^([0-9]+)/i",$_COOKIE['u_c_'],$matches))  {
    $adminId = intval($matches[1]);
    $admin->find(['uid',$adminId]);

};
global $allPrivileges;
$allPrivileges = $admin->privileges;

function havePrivilege($privilege){
    global $allPrivileges;
    if($allPrivileges=='super') return true;

    $all = preg_split("/;/",$allPrivileges);
    if(in_array($privilege,$all)){
        return true;
    }
    return false;
}
?>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title>后台管理</title>
    <link rel="stylesheet" href="css/pintuer.css">
    <link rel="stylesheet" href="css/admin.css">
    <script src="js/jquery-3.1.1.min.js"></script>
<style type="text/css">
    .leftnav h2.on {
        color: red;
    }

    a:hover, .leftnav ul li a.on {
        color:dodgerblue;
    }
</style>
</head>
<body style="background-color:#f2f9fd;">
<div class="leftnav"  style=" overflow-y:scroll;">
  <h2 class="on" style="border-top:0px;"><span class="icon-lock"></span>系统设置</h2>
   <ul style="display:block">
    <li><a href="/admin,pass" target="right"><span class="icon-caret-right"></span>修改密码</a></li>
    <li><a href="/tablemenu,list" target="right"><span class="icon-caret-right"></span>菜单列表</a></li>
       <?php
 if(havePrivilege('super')) {
     ?>
     <li><a class="on" href="/loginlog,list" target="right"><span class="icon-caret-right"></span>系统日志</a></li>
     <?php
 }
 ?>
   </ul>

    <?php
if(havePrivilege('super')) {
    $menu = new TableMenu();
    $sql = "SELECT mainName,avg(idx) as avgIdx FROM  `tbl_table_menu` WHERE status=3 group by mainName order by avgIdx ASC ";
    $result = $menu->query($sql);
    foreach($result as $tmpRow){
        $mainName = $tmpRow['mainName'];
        echo '<h2><span class="icon-pencil-square-o"></span>'.$mainName.'</h2><ul>'; //主菜单
        $sql = "SELECT * FROM `tbl_table_menu` WHERE mainName = '{$mainName}' ORDER BY idx ASC";
        $menuList = $menu->query($sql);
        foreach($menuList as $tmpMenu){
            $listName = str_replace("tbl_","",$tmpMenu['tableName']);
            $listName = str_replace("_","",$listName);

            //子菜单
            echo "<li><a href=/{$listName},list target=right><span class=icon-caret-right></span>{$tmpMenu['subName']}</a></li>";
        }
?>
</ul>
<?php
    }//end main foreach
}//end privilege
?>
</div>
<script type="text/javascript">
    $(function(){
        $(".leftnav h2").click(function(){
            $(this).next().slideToggle(200);

            $(".leftnav h2 ").removeClass("on");
            $(this).addClass("on");
        })
  $(".leftnav ul li a").click(function(){
      $("#a_leader_txt").text($(this).text());
      $(".leftnav ul li a").removeClass("on");
      $(this).addClass("on");
  })
});
</script>
<ul class="bread">
  <li><a href="/loginlog,list" target="right" class="icon-home"> 首页</a></li>
  <li><a href="#" id="a_leader_txt">网站信息</a></li>
  <li><b>当前语言：</b></li>
    <li><span style="color:red;">中文</span></li>
    <li><a class="button button-little bg-red" style="padding: 2px;" href="/admin,logout"><span class="icon-power-off"></span> 退出登录</a></li>
</ul>
<div class="admin">
  <iframe scrolling="auto" rameborder="0" src="/loginlog,list" name="right" width="100%" height="100%"></iframe>
</div>
</body>
</html>